package edu.hbsi.demo4;
import java.util.Scanner;
public class Test {
    public static void main(String[] args) {
        int[] grades = new int[5];
        int countPassed = 0, countFailed = 0;
        double sumGrades = 0.0;
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < grades.length; i++)
        try {

                System.out.print("请输入第" + (i + 1) + "个学生的数学成绩（0~100之间）: ");
                int grade = Integer.parseInt(scanner.nextLine());
                // 检查成绩是否在0到100之间
                if (grade < 0 || grade > 100) {
                    throw new NumberRangeException("成绩必须在0到100之间！");
                }
                grades[i] = grade;
                sumGrades += grade;
                if (grade >= 60) {
                    countPassed++;
                } else {
                    countFailed++;
                }


        } catch (NumberFormatException e) {
            System.out.println("输入错误，请输入有效的整数！");
        } catch (NumberRangeException e) {
            System.out.println(e.getMessage());
        } finally {
            double averageGrade = sumGrades / grades.length;
            System.out.println("及格人数: " + countPassed);
            System.out.println("不及格人数: " + countFailed);
            System.out.println("平均分: " + averageGrade);

            System.out.println("。。。。。");
            scanner.close();
        }
    }
}

